package com.xjust.service.impl;

import com.xjust.Mapper.MedicalRecordMapper;
import com.xjust.Mapper.MedicalRecordDiseaseMapper;
import com.xjust.Mapper.RegisterMapper;
import com.xjust.service.MedicalRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MedicalRecordImpl implements MedicalRecordService {
    @Autowired
   private MedicalRecordMapper medicalRecordMapper;
    @Autowired
   private MedicalRecordDiseaseMapper medicalRecordDiseaseMapper;
    @Autowired
   private RegisterMapper registerMapper;
    //保存病历
    @Override
    public void saveMedicalRecord(Map<String, Object> medicalRecord) {
        medicalRecordMapper.insert(medicalRecord);
        registerMapper.updateVisitState(medicalRecord.get("register_id"));
        List<Map<String,Object>> diseaseList = (List<Map<String, Object>>) medicalRecord.get("diseaseList");
        if(diseaseList.size()>0){
            for (Map<String, Object> disease : diseaseList) {
                HashMap<String,Object> medicalRecordDisease = new HashMap<>();
                medicalRecordDisease.put("medical_record_id",medicalRecord.get("id"));
                medicalRecordDisease.put("disease_id",disease.get("id"));
                medicalRecordDiseaseMapper.insert(medicalRecordDisease);
            }
        }
    }
    //提交看诊结果
    @Override
    public void submitDiagnosticOpinion(Map<String, Object> medicalRecord) {
        medicalRecordMapper.updateDiagnosticOpinion(medicalRecord);
    }
}
